home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 11 / Engine / Mesh.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-01  |  3.9 KB  |  92 lines

  1. //-----------------------------------------------------------------------------
  2. // Used to load and manage static and animated meshes.
  3. //
  4. // Programming a Multiplayer First Person Shooter in DirectX
  5. // Copyright (c) 2004 Vaughan Young
  6. //-----------------------------------------------------------------------------
  7. #ifndef MESH_H
  8. #define MESH_H
  9.  
  10. //-----------------------------------------------------------------------------
  11. // Frame Structure
  12. //-----------------------------------------------------------------------------
  13. struct Frame : public D3DXFRAME
  14. {
  15.     D3DXMATRIX finalTransformationMatrix; // Frame's final transformation after being combined with its parent.
  16.  
  17.     //-------------------------------------------------------------------------
  18.     // Returns the frame's translation.
  19.     //-------------------------------------------------------------------------
  20.     D3DXVECTOR3 GetTranslation()
  21.     {
  22.         return D3DXVECTOR3( finalTransformationMatrix._41, finalTransformationMatrix._42, finalTransformationMatrix._43 );
  23.     }
  24. };
  25.  
  26. //-----------------------------------------------------------------------------
  27. // Mesh Container Structure
  28. //-----------------------------------------------------------------------------
  29. struct MeshContainer : public D3DXMESHCONTAINER
  30. {
  31.     char **materialNames; // Temporary array of material (texture) names.
  32.     Material **materials; // Array of materials used by the mesh container.
  33.     ID3DXMesh *originalMesh; // Original mesh.
  34.     D3DXATTRIBUTERANGE *attributeTable; // Mesh's attribute table.
  35.     unsigned long totalAttributeGroups; // Total number of attribute groups.
  36.     D3DXMATRIX **boneMatrixPointers; // Array of pointers to the bone transformation matrices.
  37. };
  38.  
  39. //-----------------------------------------------------------------------------
  40. // Allocate Hierarchy Class
  41. //-----------------------------------------------------------------------------
  42. class AllocateHierarchy : public ID3DXAllocateHierarchy
  43. {
  44.     STDMETHOD( CreateFrame )( THIS_ LPCSTR Name, LPD3DXFRAME *ppNewFrame );
  45.     STDMETHOD( CreateMeshContainer )( THIS_ LPCSTR Name, CONST D3DXMESHDATA *pMeshData, CONST D3DXMATERIAL *pMaterials, CONST D3DXEFFECTINSTANCE *pEffectInstances, DWORD NumMaterials, CONST DWORD *pAdjacency, LPD3DXSKININFO pSkinInfo, LPD3DXMESHCONTAINER *ppNewMeshContainer );
  46.     STDMETHOD( DestroyFrame )( THIS_ LPD3DXFRAME pFrameToFree );
  47.     STDMETHOD( DestroyMeshContainer )( THIS_ LPD3DXMESHCONTAINER pMeshContainerToFree );
  48. };
  49.  
  50. //-----------------------------------------------------------------------------
  51. // Mesh Class
  52. //-----------------------------------------------------------------------------
  53. class Mesh : public BoundingVolume, public Resource< Mesh >
  54. {
  55. public:
  56.     Mesh( char *name, char *path = "./" );
  57.     virtual ~Mesh();
  58.  
  59.     void Update();
  60.     void Render();
  61.  
  62.     void CloneAnimationController( ID3DXAnimationController **animationController );
  63.  
  64.     MeshContainer *GetStaticMesh();
  65.     Vertex *GetVertices();
  66.     unsigned short *GetIndices();
  67.  
  68.     LinkedList< Frame > *GetFrameList();
  69.     Frame *GetFrame( char *name );
  70.     Frame *GetReferencePoint( char *name );
  71.  
  72. private:
  73.     void PrepareFrame( Frame *frame );
  74.     void UpdateFrame( Frame *frame, D3DXMATRIX *parentTransformationMatrix = NULL );
  75.     void RenderFrame( Frame *frame );
  76.  
  77. private:
  78.     Frame *m_firstFrame; // First frame in the mesh's frame hierarchy.
  79.     ID3DXAnimationController *m_animationController; // Animation controller.
  80.  
  81.     D3DXMATRIX *m_boneMatrices; // Array of bone transformation matrices.
  82.     unsigned long m_totalBoneMatrices; // Number of bones in the array.
  83.  
  84.     MeshContainer *m_staticMesh; // A static (non-animated) version of the mesh.
  85.     Vertex *m_vertices; // Array of vertices from the static mesh.
  86.     unsigned short *m_indices; // Array of indices into the vertex array.
  87.  
  88.     LinkedList< Frame > *m_frames; // Linked list of pointers to all the frames in the mesh.
  89.     LinkedList< Frame > *m_refPoints; // Linked list of pointers to all the reference points in the mesh.
  90. };
  91.  
  92. #endif